package com.zjsru.controller;

import com.zjsru.Service.UserInfoService;
import com.zjsru.Service.impl.LoginException;
import com.zjsru.domain.ResultInfo;
import com.zjsru.domain.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserInfoController {
    private final UserInfoService userInfoService;

    @RequestMapping("login")
    public ResultInfo login(@RequestBody UserInfo user) {
        ResultInfo info = new ResultInfo( );
            try{
                UserInfo userInfo = userInfoService.login(user.getEmail(), user.getPassword());
                info.setFlag(true);
                info.setData(userInfo);
            } catch (LoginException e) {
                String errorMsg = e.getMessage();
                info.setFlag(false);
                info.setErrorMsg(errorMsg);
            }
            return  info;
        }
    }